package io.renren.runner;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import io.renren.htby.utils.SocketUtils;
import io.renren.socket.server.DisConfigNIOServer;

//@Component
public class DisConfigNIOServerRunner  implements CommandLineRunner {
	
	private static Logger logger = LoggerFactory.getLogger(DisConfigNIOServerRunner.class);
	
	public void run(String... var1) throws Exception {
		logger.info("This will be execute when the project was started!");
		
		// 启动 分发nio服务端
		DisConfigNIOServer server1 = new DisConfigNIOServer(SocketUtils.DIS_PORT);
		new Thread(server1).start();
		
		// 将其放入 map 统一管理
		SocketUtils.ServersMap.put(SocketUtils.DIS_SERVER_KEY, server1);
	}
	
	/**
	 * 测试 启动后，再次追加 topic 主题
	 * 
	 * @author lfy.xys
	 * @date 2018年6月15日
	 *
	 * @throws Exception
	 */
	public void TestDisRun() throws Exception {
		
		// 启动 分发nio服务端
		DisConfigNIOServer server1 = new DisConfigNIOServer(SocketUtils.DIS_PORT);
		new Thread(server1).start();
		
		Thread.sleep(10000);
		server1.write("aaa".getBytes());
	}
}
